/**
 * 
 */
package lu.med.praxiswahl.wahlumed.client.addressbook;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;

/**
 * @author PatrickPierre
 *
 */
public class TableColumnWidthListener implements TableColumnModelListener {

	private AddressBookTablePanel tableObj;
	
	public TableColumnWidthListener(AddressBookTablePanel tableObj){
		this.tableObj = tableObj;
	}
	/* (non-Javadoc)
	 * @see javax.swing.event.TableColumnModelListener#columnAdded(javax.swing.event.TableColumnModelEvent)
	 */
	@Override
	public void columnAdded(TableColumnModelEvent arg0) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.swing.event.TableColumnModelListener#columnMarginChanged(javax.swing.event.ChangeEvent)
	 */
	@Override
	public void columnMarginChanged(ChangeEvent arg0) {
		
		 /* columnMarginChanged is called continuously as the column width is changed
        by dragging. Therefore, execute code below ONLY if we are not already
        aware of the column width having changed */
     if(!tableObj.getColumnWidthChanged())
     {
         /* the condition  below will NOT be true if
            the column width is being changed by code. */
         if(tableObj.getBookTable().getTableHeader().getResizingColumn() != null)
         {
        	 //System.out.println("Column width changed::"+tableObj.getTableHeader().getResizingColumn().getHeaderValue().toString());
             // User must have dragged column and changed width
             tableObj.setColumnWidthChanged(true, tableObj.getBookTable().getTableHeader().getResizingColumn());
             
         }
     }
	}

	/* (non-Javadoc)
	 * @see javax.swing.event.TableColumnModelListener#columnMoved(javax.swing.event.TableColumnModelEvent)
	 */
	@Override
	public void columnMoved(TableColumnModelEvent arg0) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.swing.event.TableColumnModelListener#columnRemoved(javax.swing.event.TableColumnModelEvent)
	 */
	@Override
	public void columnRemoved(TableColumnModelEvent arg0) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.swing.event.TableColumnModelListener#columnSelectionChanged(javax.swing.event.ListSelectionEvent)
	 */
	@Override
	public void columnSelectionChanged(ListSelectionEvent arg0) {
		// TODO Auto-generated method stub

	}

}
